package com.gdk.ksoft.assembly.utils.system;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by hel on 2014-11-29.
 * 配置辅助类
 */
public class ConfigUtils {

    public static final String CONFIG_NAME = "config.ini";
    private SharedPreferences preferences;
    private static ConfigUtils configUtils;
    private static ConfigUtils configUtils1;

    public static ConfigUtils getInstance(Context context,String configName){
        if(configUtils == null) configUtils = new ConfigUtils(context,configName);
        return configUtils;
    }

    public static ConfigUtils getInstance(Context context){
        if(configUtils1 == null) configUtils1 = new ConfigUtils(context,CONFIG_NAME);
        return configUtils1;
    }

    /**
     * 构造函数
     * @param context
     * @param configName
     */
    public ConfigUtils(Context context,String configName){
        preferences = context.getSharedPreferences(configName,Context.MODE_PRIVATE);
    }

//    /**
//     * 构造函数，使用默认配置文件名
//     * @param context
//     */
//    public ConfigUtils(Context context){
//        preferences = context.getSharedPreferences(CONFIG_NAME,Context.MODE_PRIVATE);
//    }

    /**
     * 获取配置编辑器
     * @return
     */
    public SharedPreferences.Editor getEditor(){
        return preferences.edit();
    }

    public SharedPreferences getSharedPreference(){
        return preferences;
    }

}
